home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
stv.lha
/
STV
/
st_v
/
v_pm
/
table.prj
Wrap
Text File
|
1993-07-23
|
23KB
|
734 lines
"
******************************************************************************
Project : Table
Date : 28-08-92
Time : 06:12:50 pm
Classes :
PTitlePane TableObjects MultipleSelectListBoxWH
TitlePane TableModel TableColumn ListBoxWH
Methods :
#wmMeasureitem:with: defined in TopPane.
******************************************************************************
"!
PGraphPane subclass: #PTitlePane
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''!
Object subclass: #TableObjects
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''!
MultipleSelectListBox subclass: #MultipleSelectListBoxWH
instanceVariableNames:
'userDrawn tableModel selector '
classVariableNames: ''
poolDictionaries:
'PMConstants '!
SubPane subclass: #TitlePane
instanceVariableNames:
'segId '
classVariableNames: ''
poolDictionaries:
'PMConstants '!
TableObjects subclass: #TableModel
instanceVariableNames:
'title columns contents offset '
classVariableNames: ''
poolDictionaries:
'ColorConstants '!
TableObjects subclass: #TableColumn
instanceVariableNames:
'title width renderBlock '
classVariableNames: ''
poolDictionaries: ''!
Smalltalk at: #TopPane ifAbsent: [
ApplicationWindow subclass: #TopPane
instanceVariableNames:
'handlers framingBlock '
classVariableNames: ''
poolDictionaries:
'PMConstants ']!
ListBox subclass: #ListBoxWH
instanceVariableNames:
'userDrawn tableModel selector '
classVariableNames: ''
poolDictionaries:
'PMConstants '!
!PTitlePane class methods ! !
!PTitlePane methods !
styles
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
-
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^#(noScrollBars noBorders)! !
!TableObjects class methods !
new
"private - the thinking persons new"
"wh-(24-06-92)-new"
^super new initialize! !
!TableObjects methods !
initialize
"private - do the initialization for table objects"
"wh-(26-06-92)-new"
^self! !
!MultipleSelectListBoxWH class methods !
forModel: aTableModel
"Create a new horizontally scrollable ADSC List Box"
"that will act as a view onto aTableModel."
"When the table model changes this list box will be told about it"
"and will update iits view. The table model is dependent on its underlying"
"model and will propagate the dependency upwards."
| newInstance |
newInstance := self new.
newInstance style: newInstance defaultStyle.
newInstance tableModel: aTableModel.
aTableModel addDependent: newInstance.
^newInstance.!
new
"Answer an instance of the receiver where
the owner will be notified to draw each item."
^super new initialize.!
supportedEvents
"Answer the Set of events that FormattedListBoxes can notify"
" their owners about."
^super supportedEvents
add: #horizontalScroll;
yourself.! !
!MultipleSelectListBoxWH methods !
defaultStyle
" Private - Answer the style for an horizontal scroll MultipleSelectListBoxWH "
^super defaultStyle | LsOwnerdraw | LsHorzscroll.!
drawBox
"This class was added to add portable user-drawn list
box methods like this one. Although documented by Digitalk, these
methods are not included in the base PM image."
^userDrawn boundingBox.!
drawItem: aDrawStruct
"Private - Process a request to draw a user
drawn control item.
Answer true if item was painted."
| item bMap box |
itemBeingDrawn := aDrawStruct itemId + 1.
bMap := bmaps at: itemBeingDrawn ifAbsent: [ nil ].
graphicsTool := Pen for: ( aDrawStruct hps ) medium: self.
userDrawn := aDrawStruct.
box := aDrawStruct boundingBox.
bMap isNil
ifTrue:
[
graphicsTool
place: box origin;
blank: box.
self tableModel perform: selector with: self.
itemWasDrawn := true
]
ifFalse:
[
graphicsTool erase;
copyBitmap: bMap
from: bMap boundingBox
at: box origin.
itemWasDrawn := true.
].
graphicsTool setClipRect: nil. " free region "
graphicsTool := nil. " invalidate "
^itemWasDrawn.!
drawItems: aCount
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- Send the message to pm to kick off the call back
---------------------------------------------------------------------------------------------------------------------------------------------------------"
PMWindowLibrary sendMsg: handle
msg: LmDeleteall mp1: 0 mp2: 0.
aCount timesRepeat: [
PMWindowLibrary
sendMsg: handle
msg: LmInsertitem
mp1: LitEnd
mp2Struct: 'string' ]!
initialize
" Private - Initialize the receiver. "
super initialize.
self style: (self ownerDrawFixed).
^self!
syncControlEvent: msg with: aParameter
" Private - Synchronous control message handling routine. "
msg = LnScroll
ifTrue: [ self event: #horizontalScroll ].
^super syncControlEvent: msg with: aParameter!
tableModel
"protected - comment"
"wh-(24-06-92)-new"
^tableModel.!
tableModel: anObject
"protected - comment"
"wh-(24-06-92)-new"
tableModel := anObject.!
update: aTableModel with: aSelector with: aCollection
"private - The model for this list box has changed"
"reset the contents and process the resulting drawItem"
"by sending the selector with the pane to the model to do"
"the actual drawing"
"wh-(26-06-92)-new"
| dummyContents |
selector := (aSelector asString, ':') asSymbol.
list := aCollection.
self drawItems: aCollection size!
validate
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- ignore for this box
---------------------------------------------------------------------------------------------------------------------------------------------------------"!
wmMeasureitem: mp1 with: mp2
"Private - Measure a user drawn control item."
"Note this method will only be invoked if the control is"
"in a TopPane that implements WM_MEASUREITEM."
| return width |
tableModel totalWidth.
return := PMLong
lowHalf: height
highHalf: tableModel totalWidth .
^(return asParameter).! !
!TitlePane class methods ! !
!TitlePane methods !
display
"private - the title bar needs redrawing"
"wh-(07-07-92)-new"
segId notNil
ifTrue: [ graphicsTool setClipRect: nil;
drawSegment: segId
]!
drawTitle: aPane using: tableModel
"private - Draw the column titles in the right order"
"above the listbox in a scrollable graph pane"
"wh-(26-06-92)-new"
| box x y rect |
graphicsTool foreColor: ClrDarkred;
deleteAllSegments.
rect := graphicsTool boundingBox.
y := rect origin y.
x := aPane drawBox origin x.
rect origin: x@y extent: aPane drawBox extent.
segId := graphicsTool
drawRetainPicture: [ graphicsTool erase.
tableModel columns
do: [ :each | graphicsTool setClipRect: (box := tableModel clipRectFor: each from: rect);
erase;
displayText: each title at: (((box origin x) right: (box width // 2)) left: (graphicsTool stringWidthOf: each title)//2)@y;
place: (box rightTop left: 2);
line: (box rightBottom left: 2).
]
]!
frameStyle
"Supports no scrollbars and no border styles in graphpanes."
| frameStyle |
frameStyle := FcfNobytealign.
((self propertyAt: #frameStyle) = #noBorders) ifFalse: [
frameStyle := frameStyle | FcfBorder.
].
(self propertyAt: #frameStyle) isNil ifTrue: [
frameStyle := frameStyle | FcfHorzscroll | FcfVertscroll.
].
^frameStyle.!
getGraphicsTool
"Private - Answer a graphics tool for the receiver."
"private - comment"
"wh-(30-06-92)-new"
| ps |
ps := self getPresentationSpace.
graphicsTool isNil
ifTrue: [graphicsTool := RecordingPen for: ps medium: self]
ifFalse: [ graphicsTool restoreSegments: ps ].
(PMGraphicsLibrary
setDrawControl: graphicsTool handle
control: DctlBoundary
value: DctlOn)
ifFalse: ["report draw error"].
^graphicsTool!
getPresentationSpace
"Private - Answer a PresentationSpace for the receiver."
| ps |
PMWindowLibrary openWindowDC: handle.
ps := PresentationSpaceHandle fromBytes:
(PMGraphicsLibrary createPS: PM hab
hdc: (PMWindowLibrary queryWindowDC: handle)
pgsi: (0 @ 0) asParameter
fOptions: GpiaAssoc | PuArbitrary).
ps = NullHandle ifTrue: [
self class tooManyWindows.
^nil].
^ps!
initialize
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
-
---------------------------------------------------------------------------------------------------------------------------------------------------------"
super initialize.
self noScrollBars!
noBorders
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
-
---------------------------------------------------------------------------------------------------------------------------------------------------------"
self propertyAt: #frameStyle put: #noBorders!
noScrollBars
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
-
---------------------------------------------------------------------------------------------------------------------------------------------------------"
self propertyAt: #frameStyle put: #noScrollBars!
scrollHorizontal: aPane
"private - ignore vertical"
"wh-(30-06-92)-new"!
scrollVertical: aPane
"private - ignore vertical"
"wh-(30-06-92)-new"!
specialStyle
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- Queried by WindowBuilder
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^#noScrollBars! !
!TableModel class methods ! !
!TableModel methods !
clipRectFor: aColumn from: aDrawBox
"private - for this column calculate the clipping within"
"the current bounding box"
"wh-(26-06-92)-new"
| indent |
indent := self startOf: aColumn.
^Rectangle origin: (aDrawBox origin right: indent) extent: (aColumn width@aDrawBox height + 1).!
columns
"protected - return the collection of columns"
"wh-(24-06-92)-new"
^columns.!
columns: anObject
"protected - comment"
"wh-(24-06-92)-new"
columns := anObject.!
drawStrings: aPane
"This selector has been invoked by the ADSC list box"
"to draw each of the contents as strings."
"For each column draw the obj returned by the columns selector"
"Within the column bounds"
"wh-(26-06-92)-new"
| drawIndex obj pen y box iv org x |
org := aPane drawBox origin.
y := org y up: 4.
x := org x.
(offset ~= x)
ifTrue: [ offset := x.
title notNil
ifTrue: [ title drawTitle: aPane using: self ]
].
drawIndex := aPane itemBeingDrawn.
pen := aPane pen.
obj := contents at: drawIndex.
columns do: [ :each | pen setClipRect: (box := self clipRectFor: each from: aPane drawBox);
place: (box origin x)@y;
displayText: ((iv := each renderBlock value: obj) isNil ifTrue: [ String new ] ifFalse: [ iv ]);
place: (box rightTop left: 1);
line: (box rightBottom left: 1).
].!
startOf: aColumn
"private - return the pixel start of this column"
"wh-(26-06-92)-new"
| indent |
indent := 0.
1 to: (columns indexOf: aColumn) - 1
do: [ :index | indent := indent + (columns at: index) width ].
^indent.!
title
"protected - return the title pane"
"wh-(26-06-92)-new"
^title.!
title: aPane
"protected - this is the title Pane"
"to be set up and scrolled by the TableModel object"
"wh-(26-06-92)-new"
title := aPane!
totalWidth
"private - return the total width of this table"
"wh-(26-06-92)-new"
| total |
total := 0.
columns do: [ :each| total := total + each width ].
^total!
update: aCollection with: aSelector
"private - The underlying model object collection has changed."
"We must reset our contents to be a Collection and propagate the"
"effects upwards"
"wh-(25-06-92)-new"
contents := aCollection.
self changed: self with: aSelector with: contents.! !
!TableColumn class methods ! !
!TableColumn methods !
renderBlock
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Answer the value of renderBlock.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^renderBlock!
renderBlock: aRenderBlock
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Set the value for renderBlock to aRenderBlock.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
renderBlock := aRenderBlock.!
title
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Answer the value of title.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^title!
title: aTitle
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Set the value for title to aTitle.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
title := aTitle.!
width
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Answer the value of width.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^width!
width: aWidth
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Set the value for width to aWidth.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
width := aWidth.! !
!ListBoxWH class methods !
forModel: aTableModel
"Create a new horizontally scrollable ADSC List Box"
"that will act as a view onto aTableModel."
"When the table model changes this list box will be told about it"
"and will update its view. The table model is dependent on its underlying"
"model and will propagate the dependency upwards."
| newInstance |
newInstance := self new.
newInstance style: newInstance defaultStyle.
newInstance tableModel: aTableModel.
aTableModel addDependent: newInstance.
^newInstance.!
new
"Answer an instance of the receiver where
the owner will be notified to draw each item."
^super new initialize.!
supportedEvents
"Answer the Set of events that FormattedListBoxes can notify"
" their owners about."
^super supportedEvents
add: #horizontalScroll;
yourself.! !
!ListBoxWH methods !
defaultStyle
" Private - Answer the style for an horizontal scroll ListBoxWH "
^super defaultStyle | LsOwnerdraw | LsHorzscroll.!
drawBox
"This class was added to add portable user-drawn list
box methods like this one. Although documented by Digitalk, these
methods are not included in the base PM image."
^userDrawn boundingBox.!
drawItem: aDrawStruct
"Private - Process a request to draw a user
drawn control item.
Answer true if item was painted."
| item bMap box |
itemBeingDrawn := aDrawStruct itemId + 1.
bMap := bmaps at: itemBeingDrawn ifAbsent: [ nil ].
graphicsTool := Pen for: ( aDrawStruct hps ) medium: self.
userDrawn := aDrawStruct.
box := aDrawStruct boundingBox.
bMap isNil
ifTrue:
[
graphicsTool
place: box origin;
blank: box.
self tableModel perform: selector with: self.
itemWasDrawn := true
]
ifFalse:
[
graphicsTool erase;
copyBitmap: bMap
from: bMap boundingBox
at: box origin.
itemWasDrawn := true.
].
graphicsTool setClipRect: nil. " free region "
graphicsTool := nil. " invalidate "
^itemWasDrawn.!
drawItems: aCount
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- Send the message to pm to kick off the call back
---------------------------------------------------------------------------------------------------------------------------------------------------------"
PMWindowLibrary sendMsg: handle
msg: LmDeleteall mp1: 0 mp2: 0.
aCount timesRepeat: [
PMWindowLibrary
sendMsg: handle
msg: LmInsertitem
mp1: LitEnd
mp2Struct: 'string' ]!
initialize
" Private - Initialize the receiver. "
super initialize.
self style: (self ownerDrawFixed).
^self!
syncControlEvent: msg with: aParameter
" Private - Synchronous control message handling routine. "
msg = LnScroll
ifTrue: [ self event: #horizontalScroll ].
^super syncControlEvent: msg with: aParameter!
tableModel
"protected - comment"
"wh-(24-06-92)-new"
^tableModel.!
tableModel: aTableModel
"protected - Set up the dependency link between the table model and ourselves"
"wh-(24-06-92)-new"
tableModel := aTableModel.
aTableModel addDependent: self.!
update: aTableModel with: aSelector with: aCollection
"private - The model for this list box has changed"
"reset the contents and process the resulting drawItem"
"by sending the selector with the pane to the model to do"
"the actual drawing"
"wh-(26-06-92)-new"
| dummyContents |
selector := (aSelector asString, ':') asSymbol.
list := aCollection.
self drawItems: aCollection size!
validate
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- ignore for this box
---------------------------------------------------------------------------------------------------------------------------------------------------------"!
wmMeasureitem: mp1 with: mp2
"Private - Measure a user drawn control item."
"Note this method will only be invoked if the control is"
"in a TopPane that implements WM_MEASUREITEM."
| return width |
tableModel totalWidth.
return := PMLong
lowHalf: height
highHalf: tableModel totalWidth .
^(return asParameter).! !
!TopPane methods !
wmMeasureitem: mp1 with: mp2
"Private - Measure a user drawn control item."
"Private - Dispatch the message"
"to proper window for handling."
"wh-(17-07-92)-new"
| w |
w := self childAtId: ( mp1 lowHalf ).
w isNil
ifFalse: [ ^w wmMeasureitem: mp1 with: mp2 ].
^nil! !
!SLExtra methods !
blankOut
"---------------------------------------------------------------------------------------------------------------------------------------------------------
* Private *
- This is effectively a new coverage and therefore should have the value fields blanked out.
- We can tell that it has just been instantiated from the host because the action field will be blank
---------------------------------------------------------------------------------------------------------------------------------------------------------"
action value notEmpty
ifTrue: [ reason value: String new.
annum value: String new.
last value: String new.
amount value: String new
]! !
!SLExtra methods !
expiry
"---------------------------------------------------------------------------------------------------------------------------------------------------------
- Answer the value of expiry.
---------------------------------------------------------------------------------------------------------------------------------------------------------"
^expiry! !
"construct application"
((Smalltalk at: #Application ifAbsent: [])
isKindOf: Class) ifTrue: [
((Smalltalk at: #Application) for:'Table')
addClass: PTitlePane;
addClass: TableObjects;
addClass: MultipleSelectListBoxWH;
addClass: TitlePane;
addClass: TableModel;
addClass: TableColumn;
addClass: ListBoxWH;
addMethod: #wmMeasureitem:with: forClass: TopPane;
addMethod: #blankOut forClass: SLExtra;
addMethod: #expiry forClass: SLExtra;
comments: nil;
initCode: nil;
finalizeCode: nil;
startUpCode: nil]!